import { Component, OnInit } from '@angular/core';
import { MerchantcashrecordService } from '../../service/merchantcashrecord.service';
import { MerchantinfoService } from '../../service/merchantinfo.service';
import { NzMessageService } from 'ng-zorro-antd';
import { CommonService } from 'src/app/service/common.service';
import { ComponentBasic } from '../../app.component';
import { RoleRight } from '../../../kalend';
@Component({
  selector: 'app-merchantinfo',
  templateUrl: './merchantscash.component.html',
  styleUrls: ['./merchantscash.component.scss'],
  providers: [MerchantcashrecordService, CommonService,MerchantinfoService]
})
export class MerchantscashComponent extends ComponentBasic implements OnInit {
  loading = true;
  pageIndex = 1;
  pageSize = 15;
  total = 1;
  doc: any = {};
  dataSet = [];
  sdate: any;
  edate: any;
  iscontact:any;
  remarks:any;
  auditstatus:any;
  //提现金额
  cashmoney:any;
  isVisible=false;
  isCrshVisible=false;
  isOkLoading=false;
  footTotal:any;
  LoginUser=RoleRight.getStorage();
  statuslist = [{ key: null, value: '全部' }, { key: 1, value: '审核通过' }, { key: 0, value: '审核中' }, { key: 2, value: '审核拒绝' }];
  constructor(private merchantinfoService: MerchantinfoService,private merchantcashrecord:MerchantcashrecordService, private msg: NzMessageService, private commonservice: CommonService) {
    super();
    super.setLayout(true, true);
  }

  ngOnInit() {

    this.searchData();
  }
  searchData(reset: boolean = false): void {
    this.loading = true;
    this.merchantcashrecord.querybypage({
      offset: this.pageIndex,
      limit: this.pageSize,
      userid:this.LoginUser._id,
      auditstatus:this.auditstatus,
      sdate:this.sdate,
      edate:this.edate

    }).then((res) => {
      this.loading = false;
      this.total = res.total;
      this.dataSet = res.rows.map((item)=>{
       item.cashchannel=item.cashchannel=="wechat"?'微信零钱':'银行卡';
       return item;
      });
      this.footTotal= res.footTotal;
    });
  }

  edit(id):void{
    this.isVisible = true;
    this.merchantinfoService.queryone({_id:id}).then((res) => {
      this.doc = res;
    });
  }

  crsh(id):void{
    this.isVisible=true;
    this.merchantinfoService.queryone({_id:id}).then((res) => {
      this.doc = res;
    });

  }

  //确定提交
  handleOk(): void {
    let parm={
      totalcase:this.cashmoney,
      BankCardNo:this.doc.BankCardNumber,
      merchantid:this.doc._id,
      Bank:this.doc.Bank
    }
      this.merchantcashrecord.create(parm).then((res) => {
        this.searchData();
        this.isVisible = false;
        this.doc = {};
      });
    
  }

  handleCancel(): void {
    this.isVisible = false;
    this.doc = {};
  }
}
